var tabnum = 0;
var maxtabnum = 2;
$(document).ready(function() {
	var parwinwidth = $(parent.window).width();
	var parwinheight = $(parent.window).height();
	$("#leftButton,#rightButton").hover(function(){
		$(this).removeClass("transparent_0");
		$(this).addClass("transparent_class");
	},function(){
		$(this).removeClass("transparent_class");
		$(this).addClass("transparent_0");
	});
	$(".subtab").tabSwitch("create", {type: "slide", height: parwinheight*0.8, width: parwinwidth/2-5},function(){});
	
	getAnimation();
	
	$("#content1").popeScroll({
		mousewheelBox:"box1",
		offset_top:-280,
		top:35
	});
	$("#content2").popeScroll({
		mousewheelBox:"box2",
		offset_top:-60,
		top:35
	});
	$("#content3").popeScroll({
		mousewheelBox:"box3",
		offset_top:-60,
		top:35
	});
	$("#scroll_content1").show();
	$("#scroll_content2").hide();
	$("#scroll_content3").hide();
	
	
	$("#animation_year a").click(function(){
		var year = $(this).text();
		var area = $("#animation_area .fenlei_on").text();
		$("#animation_year a").attr("class","");
		$(this).attr("class","fenlei_on");
		searchAnimation(year,area);
	});
	$("#animation_area a").click(function(){
		var area = $(this).text();
		var year = $("#animation_year .fenlei_on").text();
		$("#animation_area a").attr("class","");
		$(this).attr("class","fenlei_on");
		searchAnimation(year,area);
	});
	
	$(window).resize(function() {
		refresh();
	});	
	refresh();

});

function getAnimation(){
	$.getJSON("video_getVideoByType.do",{num:50,type:"3"},function(json){
		$("#animation_content").empty();
		for(var i=0;i<json.length;i++){
			var length = json[i].tv_set_now;
			var htmlStr = '<div class="animation_div" style="width: 32%;padding-left:1%;padding-top:20px;float: left;">';
			htmlStr+= '<div class="imgdiv" style="padding-top:10px;padding-left:20%;float:left;width: 60%;">';
			htmlStr+= '<img class="imgss" onclick="showCartoon(this)" id="img_'+ json[i].id +'" src="'+ json[i].ver_big_pic +'" style="width:100%;cursor:pointer;border:#f8f7f0 2px solid;" />';
			htmlStr+= '</div>';
			var name = json[i].tv_name;
			if(name.length>10){
				name = name.substring(0,8)+"...";
			}
			htmlStr+= '<div class="animation_name" style="padding-left:20%;width: 50%;line-height: 20px;padding-top: 5px;font-size: 12px;float:left;text-align: center;"><a  id="a_'+ json[i].id +'" onclick="showCartoon(this)">'+ name +'</a></div>';
			
			/**var height = (parseInt((length-1)/7)+1)*22;
			htmlStr+= '<div style="float: left;width: 15%;padding-top: 5px;cursor: pointer;">';
			htmlStr+= '<img style="width: 20px;" id="open_list_img_'+ json[i].id +'" src="../../image/cover/others/white/MB_0019_plus.png" title="全部剧集" onclick="openList(this,'+ height +',3);" />';
			htmlStr+= '<img style="width: 20px;display: none;" id="close_list_img_'+ json[i].id +'" src="../../image/cover/others/white/MB_0019_plus2.png" title="全部剧集" onclick="closeList(this);" />';
			htmlStr+= '</div>';
			htmlStr+= '<div id="animation_list_'+ json[i].id +'" style="display:none;">';
			htmlStr+= '<div style="width:300px;float:left;color:#fff;background: url(../../image/bg/10.png);font-size:12px;line-height:20px;border:#fff solid 1px;">';
			htmlStr+= '<div class="list">';
			for(var j=1;j<=length;j++){
				htmlStr+= '<a>'+ j +'集&nbsp;</a>';
				if(j%7==0){
					htmlStr+= '</div><div class="list">';
				}else if(j==length){
					htmlStr+= '</div>';
				}
			}
			htmlStr+= '</div>';**/
			htmlStr+= '</div>';
			htmlStr+= '</div>';
			$("#animation_content").append(htmlStr);
		}		
		refresh();
	});
}
function searchAnimation(year,area){
	$.getJSON("video_getVideoByYearAndArea.do",{num:50,type:"3",year:year,area:area},function(json){
		$("#animation_content").empty();
		for(var i=0;i<json.length;i++){
			var length = json[i].tv_set_now;
			var htmlStr = '<div class="animation_div" style="width: 32%;padding-left:1%;padding-top:20px;float: left;">';
			htmlStr+= '<div class="imgdiv" style="padding-top:10px;padding-left:20%;float:left;width: 60%;">';
			htmlStr+= '<img class="imgss" onclick="showCartoon(this)" id="img_'+ json[i].id +'" src="'+ json[i].ver_big_pic +'" style="width:100%;cursor:pointer;border:#f8f7f0 2px solid;" />';
			htmlStr+= '</div>';
			var name = json[i].tv_name;
			if(name.length>10){
				name = name.substring(0,8)+"...";
			}
			htmlStr+= '<div class="animation_name" style="padding-left:20%;width: 50%;line-height: 20px;padding-top: 5px;font-size: 12px;float:left;text-align: center;"><a  id="a_'+ json[i].id +'" onclick="showCartoon(this)">'+ name +'</a></div>';
			
			/**var height = (parseInt((length-1)/7)+1)*22;
			htmlStr+= '<div style="float: left;width: 15%;padding-top: 5px;cursor: pointer;">';
			htmlStr+= '<img style="width: 20px;" id="open_list_img_'+ json[i].id +'" src="../../image/cover/others/white/MB_0019_plus.png" title="全部剧集" onclick="openList(this,'+ height +',3);" />';
			htmlStr+= '<img style="width: 20px;display: none;" id="close_list_img_'+ json[i].id +'" src="../../image/cover/others/white/MB_0019_plus2.png" title="全部剧集" onclick="closeList(this);" />';
			htmlStr+= '</div>';
			htmlStr+= '<div id="animation_list_'+ json[i].id +'" style="display:none;">';
			htmlStr+= '<div style="width:300px;float:left;color:#fff;background: url(../../image/bg/10.png);font-size:12px;line-height:20px;border:#fff solid 1px;">';
			htmlStr+= '<div class="list">';
			for(var j=1;j<=length;j++){
				htmlStr+= '<a>'+ j +'集&nbsp;</a>';
				if(j%7==0){
					htmlStr+= '</div><div class="list">';
				}else if(j==length){
					htmlStr+= '</div>';
				}
			}
			htmlStr+= '</div>';**/
			htmlStr+= '</div>';
			htmlStr+= '</div>';
			$("#animation_content").append(htmlStr);
		}
		refresh();
	});
}
function search(){
	var key = $("#searchInput").val();
	if(key==null||key==""){
		return;
	}
	$.getJSON("video_getVideoByLikeName.do",{videoLikeName:key,type:3},function(json){
		$("#search_content").empty();
		$("#navigation").empty();
		$("#search_tip").hide();
		var num=0;
		var htmlStr='';
		var htmlStrs="";
		if(json.length<1){
			$("#search_tip").show();
			$("#search_tip").html("您搜索的资源我们没有找到，我们会尽快为您添加");
			return false;
		}
		for(var i=0;i<json.length;i++){
			var t = json[i].type;
			var tName = json[i].typeName;
			var videos = json[i].videos;
			htmlStrs+='<div id="search_content-'+ t +'" class="subtabs">';
			for(var j=0;j<videos.length;j++){
				var name = videos[j].tv_name;
				var pic = videos[j].ver_big_pic;
				if(name.length>10){
					name = name.substring(0,8)+"...";
				}
				if(pic==null||pic==""){
					pic = videos[j].tv_big_pic;
				}
				htmlStrs+='<div class="search_div" style="width: 32%;padding-left:1%;padding-top:20px;float: left;">';
				htmlStrs+='<div class="imgdiv" style="padding-top:10px;padding-left:20%;float:left;width: 60%;">';
				htmlStrs+='<img class="imgss" onclick="showCartoon(this)" id="+searchImg_'+ videos[j].id +'" src="'+ pic +'" style="width:100%;cursor:pointer;border:#f8f7f0 2px solid;" />';
				htmlStrs+='</div>';
				htmlStrs+='<div class="search_name" style="padding-left:20%;width: 60%;line-height: 20px;padding-top: 5px;font-size: 12px;float:left;text-align: center;"><a onclick="showCartoon(this)">'+ name +'</a></div>';
				htmlStrs+='</div>';
			}
			htmlStrs+='</div>';
		}
		$("#navigation").append(htmlStr);
		$("#search_content").append(htmlStrs);
		$(".subtabs").hide();
		$("#search_content-1").show();
		refresh();

	});
}
function collection_search(){
	var key = $("#collectionInput").val();
	if(key==null||key==""){
		return;
	}
	
	$.getJSON("personcollection_searchCollection.do",{likeName:key,type:3},function(json){
		$("#collection_content").empty();
		$("#collection_navigation").empty();
		$("#collection_tip").hide();
		var htmlStrs="";
		if(json.length<1){
			$("#collection_tip").show();
			$("#collection_tip").html("您还没有添加收藏");
			return false;
		}
		
		for(var i=0;i<json.length;i++){
			var name = json[i].tv_name;
			var pic = json[i].ver_big_pic;
			if(name.length>10){
				name = name.substring(0,8)+"...";
			}
			if(pic==null||pic==""){
				pic = json[i].tv_big_pic;
			}
			htmlStrs+='<div class="collection_div" style="width: 32%;padding-left:1%;padding-top:20px;float: left;">';
			htmlStrs+='<div class="imgdiv" style="padding-top:10px;padding-left:20%;float:left;width: 60%;">';
			htmlStrs+='<img class="imgss" onclick="showCartoon(this)" id="+collectionImg_'+ json[i].id +'" src="'+ pic +'" style="width:100%;cursor:pointer;border:#f8f7f0 2px solid;" />';
			htmlStrs+='</div>';
			htmlStrs+='<div class="search_name" style="padding-left:20%;width: 60%;line-height: 20px;padding-top: 5px;font-size: 12px;float:left;text-align: center;"><a onclick="showCartoon(this)">'+ name +'</a></div>';
			htmlStrs+='</div>';
		}
		htmlStrs+='</div>';
		
		$("#collection_content").append(htmlStrs);
		$(".subtabs").hide();
		$("#collection_content-1").show();
		refresh();

	});
}
function refresh(){
	var winheight = $(window).height();
	var winwidth = $(window).width();
	
	$("#bodydiv").css("height",winheight);
	$("#tabscontent").css("height",winheight);
	$(".subtab").css("height",winheight-5);
	$(".content").css("height",winheight-120);
	$(".imgss").css("height",winwidth*0.32*0.6*1.375);
}

function showCartoon(obj){
	var id = obj.id.split("_")[1];
	window.parent.resizeWin("cartoon1",0.6,0.9);
	window.location.href = "showCartoon.html?id="+id;
}

function changeTab(num){
	var tmp = tabnum + num;
	if(tmp < 0|| tmp > maxtabnum){
		return;
	}
	tabnum = tmp;
	$(".subtab").tabSwitch("moveTo",{index: tabnum},function(){
		$(".popeScroll").hide();
		$("#scroll_content"+(tabnum+1)).show();
	});
}